using System.Xml;
using System;
using System.Collections.Generic;
using System.Text;

namespace AppConfiguration
{
    public class ConfigReader
    {
        #region Declarations

        private static XmlDocument _xmlConfigDoc;
        private static ConfigReader _ConfigurationReader;
        private const string AppConfigPath = "c:\\CRMConfig\\app.config";

        #endregion

        #region Constructors

        public static ConfigReader GetInstance()
        {
            if (_ConfigurationReader == null)
            {
                _ConfigurationReader = new ConfigReader();
            }
            return _ConfigurationReader;
        }

        public ConfigReader()
        {
            _xmlConfigDoc = new XmlDocument();
            _xmlConfigDoc.Load(AppConfigPath);
        }

        public string GetNodeValue(string NodePath)
        {
            XmlNode XMLNode = _xmlConfigDoc.SelectSingleNode(NodePath);

            return XMLNode != null ? XMLNode.InnerText : string.Empty;
        }


        public string GetPropertyValue(string NodePath, string PropertyName)
        {
            XmlNode XMLNode = _xmlConfigDoc.SelectSingleNode(NodePath);

            if (XMLNode != null)
            {
                if (XMLNode.Attributes[PropertyName] != null)
                {
                    return XMLNode.Attributes[PropertyName].Value;
                }
            }
            return string.Empty;
        }



        #endregion

        #region Properties

        public string LoadBalanceServer
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/LoadBalanceServer").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public string crmserviceurl
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/CrmServiceUrl").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public string AdminUserName
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/AdminUserName").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public string AdminPassword
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/AdminPassword").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public string AdminDomain
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/AdminDomain").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public int AuthenticationType
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return int.Parse(_xmlConfigDoc.SelectSingleNode("//configuration/AuthenticationType").Attributes["value"].Value);

                return 0;
            }
        }

        public string ConnString
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/ConnString").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public string ConnStringForAjax
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/ConnStringForAjax").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public string CRMServer
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/CRMServer").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public string OrgName
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/OrgName").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public string MailContentDetails
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/MailContentDetails").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public string EncryptedAdminUserName
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/EncryptedAdminUserName").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public string EncryptedAdminPassword
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/EncryptedAdminPassword").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public string SendmailToNoOfLevels
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/SendmailToNoOfLevels").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public string MailToUser
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/MailToUser").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public string ServerAddress
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/ServerAddress").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public string OrganizationName
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/OrganizationName").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public string DiscoveryUri
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/DiscoveryUri").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public string OrganizationUri
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/OrganizationUri").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public string UserName
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/UserName").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public string Domain
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/Domain").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public string EndpointType
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/EndpointType").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public string HomeRealmUri
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/HomeRealmUri").Attributes["value"].Value;

                return string.Empty;
            }
        }

        public string UserPrincipalName
        {
            get
            {
                if (_xmlConfigDoc != null)
                    return _xmlConfigDoc.SelectSingleNode("//configuration/UserPrincipalName").Attributes["value"].Value;

                return string.Empty;
            }
        }

        #endregion

    }
}

